package com.ztgf.order.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.order.models.service.IOrderRepetitionPayService;
import com.ztgf.order.models.bo.OrderRepetitionPayBO;
import com.ztgf.order.models.dto.OrderRepetitionPayDTO;

/**
 * 订单重复支付信息控制器
 *
 * @author YUE
 * @Date 2020-08-25 14:39:40
 */

@RestController
@RequestMapping("/api/orderRepetitionPay")
@Slf4j
@Api(value = "OrderRepetitionPayApiController",tags = "订单重复支付信息Api接口")
public class OrderRepetitionPayApiController {

    @DubboReference
    private IOrderRepetitionPayService orderRepetitionPayService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<OrderRepetitionPayDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        OrderRepetitionPayDTO dto = orderRepetitionPayService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "订单重复支付信息列表",notes = "订单重复支付信息列表")
    @PostMapping("/queryPageList")
    public Result<Page<OrderRepetitionPayDTO>> queryPageList(OrderRepetitionPayBO bo){
        Wrapper<OrderRepetitionPayDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<OrderRepetitionPayDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = orderRepetitionPayService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
